
function  loadData(){
    $("#jqGrid").jqGrid($.extend(jqGrids.defaults,{
        url:base+ '/app/view/list',
        colNames:[ 'ID','系统名称','系统KEY', '创建人', '创建时间','修改人','修改时间','状态','描述','<div align="center" >操作</div>'],
        colModel: [
            {name:'id',index:'id',hidden:true},
            {name:'appName',index:'appName',width:'132'},
            {name:'appKey',index:'appKey',width:'132'},
            {name:'createBy',index:'createBy',width:'120'},
            {name:'createTime',index:'createTime',width:'180',formatter:tools.formatDate},
            {name:'modifyBy',index:'modifyBy',hidden:true},
            {name:'modifyTime',index:'modifyTime',hidden:true,formatter:tools.formatDate},
            {name:'isEnabled',index:'isEnabled',width:'100',formatter:function(value,options,rData){
                return  value=='1'?'启用':'禁用';
            }},
            {name:'description',index:'description'},
            {name:'id',index:' ',width:'140',align:'center',formatter : function(value, options, rData){
                return "<a href='javascript:void(0)' onclick=doEdit(\""+value+"\")><span class='btn btn-sm purple'>编辑</span></a>"
            }}
        ]
    }));

}

function doEdit(id) {
    var url = base+ "/app/uc/edit?id=" + id + "&type=edit";
    window.location.href=url;
}

function doAdd(id) {
    var url =base+ "/app/uc/edit?id=" + id + "&type=add";
    window.location.href=url;
}


/**
 *删除
 */
function doDelete() {
    var ids=$('#jqGrid').jqGrid('getGridParam','selarrrow');
    if (ids.length<=0) {
        $.messager.alert("请选择需要删除的数据项");
        return;
    }
    var url =base+"/app/dh/delete";
    $.messager.confirm("你确定要删除选中的记录吗?", function (ck) {
        if(ck){
            $.post(url, {ids: ids}, function (data) {
                $.messager.alert0({selector: "#indexAlert", type: data.code, html: data.message});
                if (data && data.code == 'SUCCESS') {
                   $("#jqGrid").trigger("reloadGrid");
                }
            });
        }})
}

/**查询*/
function doSearch(){
    var appNameCn=$("input[name=appNameCn]").val();
    var appNameEn=$("input[name=appNameEn]").val();
    var createBy=$("input[name=createBy]").val();
    var isEnabled=$("select[name=isEnabled]").val();

    $("#jqGrid").jqGrid('setGridParam',{
        datatype:'json',
        postData:{'appNameCn':appNameCn,'appNameEn':appNameEn,'createBy':createBy,'isEnabled':isEnabled}, //发送数据
        page:0
    }).trigger("reloadGrid"); //重新载入
}
function doSubmit(type) {
    if (!formCheck().form()) {
        return;
    }
    var url;
    if ("add" == type) {
        url = base + "/app/sk/insert";
    } else {
        url = base + "/app/uc/update";
    }
    $.post(url, $("#editForm").serialize(), function (data) {
        $.messager.alert0({selector: "#editAlert", type: data.code, html: data.message});
        if (data && data.code == 'SUCCESS') {
            tools.goto(base + "/app/view/index", 500);
        }
    }, "json");

}

function formCheck() {
    return $('#editForm').validate({
        rules: {
            appNameCn: {
                maxlength:[24],
                required:true
            },
            appNameEn: {
                maxlength:[24],
                required:true
            }
        }
    });
}
